call_method = function(name,type) {
	//alert(name+"--+");
	if(type == STRING) { //the name's type is string
		//alert("in method");
		currentMethod = find_method(name,type);
		if(currentMethod == null) {
			alert("Not Found:" + name);
			return;
		}
		//alert(currentMethod);
		//testframe();
		var newFrame = new callFrame();
		newFrame.method = currentMethod;
		callStack.push(newFrame);
		currentFrame = callStack[callStack.length-1];
		//alert(currentFrame);
		currentFrame.execute(); //execute the method of current frame
		if(callStack.length > 1)
			currentFrame = callStack[callStack.length-2];
		else
			currentFrame = null;
		callStack.pop();
		alert("done");
	}
}

find_method = function(name,type) {
	//alert("in find_method");
	for(i in mainclass.methods) {
		//alert("methods: "+i);
		if(get_constant_value(mainclass.methods[i].name_index) == name) {
			//alert("find "+name);
			//execute the found method, construct a new frame, and push it into the callStack
			return mainclass.methods[i];
		}
	}
	return null;
}

//get the strings from constant pool
get_constant_value = function(id) {
	//alert("id: "+id);
	//tag == 1: UTF8, return: string
	if(mainclass.constant_pool[id].tag == 1) {
		stringValue = "";
		for(everyChar in mainclass.constant_pool[id].bytes) {
			charValue = String.fromCharCode(mainclass.constant_pool[id].bytes[everyChar]);
			stringValue += charValue;
		}
		//alert(stringValue);
		return stringValue;
	//tag == 5, long, return: long
	} else if(mainclass.constant_pool[id].tag == 5) {

	//tag == 6, double, return: double
	} else if(mainclass.constant_pool[id].tag == 6) {

	//tag == 7, class, return: classname
	} else if(mainclass.constant_pool[id].tag == 7) {
		classValue = "";
		classid = mainclass.constant_pool[id].name_index;
		for(everyChar in mainclass.constant_pool[id].bytes) {
			charValue = String.fromCharCode(mainclass.constant_pool[id].bytes[everyChar]);
			classValue += charValue;
		}
		//alert(classValue);
		return classValue;
	//tag == 8, string, return: string
	} else if(mainclass.constant_pool[id].tag == 8) {
		stringValue = "";
		stringid = mainclass.constant_pool[id].string_index;
		for(everyChar in mainclass.constant_pool[id].bytes) {
			charValue = String.fromCharCode(mainclass.constant_pool[id].bytes[everyChar]);
			stringValue += charValue;
		}
		alert(stringValue);
		return stringValue;
	//tag == the tag, F_M_I
	} else if(mainclass.constant_pool[id].tag == 9 ) {

	//tag == 12, name and type, unknown, return:unknown
	} else if(mainclass.constant_pool[id].tag == 12) {

	}
}
